home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8058 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: nababs@qualcomm.com (Nasser Abbasi)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Re: enum expression is IF statement
  5. Date: 13 Feb 1996 23:51:38 -0000
  6. Organization: Qualcomm Inc.
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: devitto@ferndown.ate.slb.com
  9. Message-ID: <4fr86a$3su@netlab.cs.rpi.edu>
  10. References: <4fq7dc$pac@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: 13 Feb 1996 22:38:04 GMT
  13.  
  14. In article <4fq7dc$pac@netlab.cs.rpi.edu>, 
  15. P.v.Klaveren@bcs.cs.philips.com says...
  16. >
  17. >enum
  18. >{
  19. >   CSEQ_IDLE,
  20. >   CSEQ_ERROR,
  21. >   CSEQ_ABORT,
  22. >   CSEQ_WAIT4RESPONSE
  23. >};
  24. >
  25. >int state = 3;
  26. >
  27. >if (state == CSEQ_WAIT4RESPONSE)
  28. >{
  29. >    // this code is not executed!!!
  30. >    ...
  31. >}
  32. >
  33. >BOOL expr_is_valid = state == CSEQ_WAIT4RESPONSE;
  34. >
  35. >if (expr_is_valid)
  36. >{
  37. >    // this code IS executed!!!
  38. >    ...
  39. >}
  40. >
  41. >
  42. >I know it is not recommended to compare integers with enumeration
  43. >values, but why on earth is 'expr_is_valid' TRUE but seems
  44. >'state == CSEQ_WAIT4RESPONSE' to result in FALSE (at least in a if
  45. >expression calcuation)?
  46. >
  47.  
  48. The code works fine on my C++ compiler (Visuall C++ 1.51).
  49. i.e. both IF statments above get executed (as one would expect).
  50.  
  51. can you post a small complete example (with #include statments) that 
  52. shows the problem? 
  53.  
  54. what compiler are you using? 
  55.  
  56. Nasser
  57.  
  58.  
  59.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  60.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  61.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  62.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  63.